/**
 * @author:albert
 */
package com.bkbw.live.battle.business.ai;

import org.apache.commons.logging.Log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.badlogic.gdx.ai.btree.Task;
import com.badlogic.gdx.ai.msg.Telegram;
import com.bkbw.live.common.GameConfig;
import com.bkbw.live.battle.business.BuildingObject;
import com.bkbw.live.battle.business.UnitObject;

public class BtAttack<EntityType extends UnitObject> extends BaseLeafNode<EntityType>{
	//protected long searchMillis = System.currentTimeMillis();
	Logger logger = LoggerFactory.getLogger(GameConfig.LoggerName);
	@Override
	public com.badlogic.gdx.ai.btree.Task.Status execute() {
		
		// TODO Auto-generated method stub
		EntityType entity = getObject();
		
		if (entity == null) {
			return Status.FAILED;
		}
		
		if (entity.isMoving()) {
			return Status.FAILED;
		}
		
		if (entity.getNormalAttack().isSpelling()) {
			entity.doNormalAttack();
			//logger.debug("is spelling");
//			if (entity.switchTargetEnemyByHateWhenAttack()) {
//				return Status.SUCCEEDED;
//			}
		
			return Status.RUNNING; 
		}
		if (entity.isTargetAttackable() && entity.isTargetInDistance()) {
//			if (entity.getNormalAttack().isAvailable()) {
//				entity.doNormalAttack();
//			}
//			if (entity.switchTargetEnemyByHateWhenAttack()) {
//				return Status.SUCCEEDED;
//			}
			//logger.debug("attack state");
			
			entity.doNormalAttack();
			//logger.debug("attack running");
			return Status.RUNNING; 
		}
		else {
			//logger.debug("attack fail");
			return Status.FAILED;
		}
		
	}

	@Override
	protected Task<EntityType> copyTo(Task<EntityType> paramTask) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean handleMessage(Telegram paramTelegram) {
		// TODO Auto-generated method stub
		return false;
	}
	
}
